package com_.dxy_test_.teststream;

import cn.hutool.core.collection.CollUtil;

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * @Description 测试流式编程
 * @Author dangxianyue
 * @Date 2024/6/12 23:18
 */
public class Test {

    public static void main(String[] args) {
        test1();
    }

    private static void test1() {
        List<User> list = CollUtil.newArrayList(
                new User(1, "A"),
                new User(2, "B"),
                new User(3, null),
                new User(4, "D")
        );

        List<String> nameList1 = list.stream().map(User::getName).collect(Collectors.toList());
        System.out.println(nameList1);

        List<String> nameList2 = list.stream().map(User::getName).filter(Objects::nonNull).collect(Collectors.toList());
        System.out.println(nameList2);
    }
}
